//
//  DateBtn.swift
//  NewDelivery
//
//  Created by 天下宅 on 2016/12/19.
//  Copyright © 2016年 天下宅. All rights reserved.
//

import UIKit

class DateBtn: UIView,WKPopDateViewResult {

    
    private var titleLabel = UILabel()
    private var dateLabel = UILabel()
    
    var isOK = false //是否有值
    
    var thisTitle:String = ""
    {
        didSet{
            titleLabel.text = thisTitle
        }
    }
    var date:String = "asdasdadad"
    {
        didSet{
            dateLabel.text = date
        }
    }
    
    var dateView:WKPopDateView = WKPopDateView()

    
    init(withTitle title:String) {
        
        super.init(frame: CGRect.init(x: 0, y: 0, width: screenWidth / 2.0, height: 40))
        
        self.titleLabel.textAlignment = NSTextAlignment.left
        self.titleLabel.font = UIFont.systemFont(ofSize: 16)
        self.addSubview(titleLabel)
        self.titleLabel.snp.makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            make.width.lessThanOrEqualTo(100)
        }
        self.titleLabel.text = title
        
        self.addSubview(self.dateLabel)
        self.dateLabel.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(titleLabel.snp.right)
            make.width.lessThanOrEqualTo(100)
        }
        
        
        self.dateLabel.textAlignment = NSTextAlignment.left
        self.dateLabel.font = UIFont.systemFont(ofSize: 16)
        self.addTarget(controlEvent: WKTapState.touchUpInside, target: self, handler: DateBtn.popDateView)

    }
    
    func popDateView(v:UIView)
    {
        dateView.thisDelegate = self
        dateView.show(flag: true)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    static func  createDateBtn(WithTitle title:String) -> DateBtn
    {
        let b = DateBtn.init(withTitle: title)
        return b
    }
    
    func getResult(_ result: String) {
        date = result
        isOK = true
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
